import charts from './Charts'
import { configsTodefaultValue } from '@/utils/core'

const has = function (type) {
  return Object.prototype.hasOwnProperty.call(charts, type)
}

const get = function (type) {
  if (has(type)) {
    return charts[type]
  }
}

const getProperty = function (type, key, defaultValue) {
  const item = get(type)
  return item && item[key] ? item[key] : defaultValue
}

const getChart = function (type) {
  return getProperty(type, 'Chart')
}

const getRequestFields = function (type) {
  return getProperty(type, 'requestFields')
}

const getConfigs = function (type) {
  return getProperty(type, 'configs')
}

const getConfigsDefaultValue = function (type) {
  const configs = this.getConfigs(type)
  if (configs) {
    return configsTodefaultValue(configs)
  }
}

export default {
  get charts() {
    return charts
  },
  get types() {
    return Object.keys(charts)
  },
  has,
  get,
  getProperty,
  getChart,
  getRequestFields,
  getConfigs,
  getConfigsDefaultValue
}
